package com.vehicle.controller;


import com.vehicle.service.ParkingLotService;
import com.vehicle.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 校园车辆管理系统
 * @since 2023-04-21
 */
@RestController
@RequestMapping("/parking-lot")
public class ParkingLotController {

    @Autowired
    ParkingLotService parkingLotService;

    //获取所有车位信息
    @GetMapping("/parkingList/{page}/{size}")
    public ResultVO getParkingList(@PathVariable("page") String page, @PathVariable("size") String size){
        return ResultVO.succ(parkingLotService.getAllParkingList(Integer.parseInt(page),Integer.parseInt(size)));
    }

    //根据区域关键字进行查询
    @GetMapping("/parkingList/{searchValue}")
    public ResultVO getParkingList(@PathVariable("searchValue") String searchValue){
        return ResultVO.succ(parkingLotService.getParkingByContent(searchValue));
    }

    @GetMapping("/getLocation/{parkingId}")
    public String getLocationByParkingId(@PathVariable("parkingId") Integer parkingId){
       return parkingLotService.getParkingLocation(parkingId);
    }

    @PutMapping("/{parkingId}/{state}")
    public Boolean updateParkingState(HttpServletRequest request, @PathVariable("parkingId") Integer parkingId, @PathVariable("state") Integer state){
        String ip = request.getRemoteAddr();
        String aid = request.getHeader("id");
        return parkingLotService.updateParkingState(ip,Integer.parseInt(aid),parkingId,state);
    }


}

